﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.IO;
using BlueFox.Qcloud;
using Newtonsoft.Json;
using System.Text.RegularExpressions;

namespace Qcloud.Test
{
    class Demo
    {
        public int result { get; set; }
        public string errMsg { get; set; }
        public string ext { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {

            var matches = Regex.Matches("尊敬的会员，您重置密码的验证码是：{code}，请于{time}分钟内输入，请勿外泄。询{tel}", @"\{.*?\}", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);

            foreach (Match item in matches)
            {
                Console.WriteLine(item.Value);
            }

            Console.ReadKey();
            return;

            var builder = new ConfigurationBuilder()
           .SetBasePath(Directory.GetCurrentDirectory())
           .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
           .AddEnvironmentVariables();

            IConfigurationRoot configuration = builder.Build();

            var service = new ServiceCollection()
            .AddQcloudSms(configuration.GetSection("sms"))

            .AddScoped<SmsSendService>()//需要哪个就添加哪个
            .BuildServiceProvider();


            // 请根据实际 appid 和 appkey 进行开发，以下只作为演示 sdk 使用
            // appid,appkey,templId申请方式可参考接入指南 https://www.qcloud.com/document/product/382/3785#5-.E7.9F.AD.E4.BF.A1.E5.86.85.E5.AE.B9.E9.85.8D.E7.BD.AE
            string phoneNumber1 = "19977196515";
            string phoneNumber2 = "18587910306";
            int tmplId = 60500;

            try
            {
                var sms = service.GetService<SmsSendService>();

                //var res1 = sms.SingleSend(0, "86", phoneNumber2, "尊敬的会员，您重置密码的验证码是：123456，请于15分钟内输入，请勿外泄。询4008819016", "", "");
                //Console.WriteLine(JsonConvert.SerializeObject(res1));

                List<string> templParams = new List<string>();
                templParams.Add("098765");

                //var res2 = sms.SingleSendWithParam("86", phoneNumber2, tmplId, templParams, "", "", "");
                //Console.WriteLine(JsonConvert.SerializeObject(res2));

                List<string> phoneNumbers = new List<string>();
                phoneNumbers.Add(phoneNumber1);
                phoneNumbers.Add(phoneNumber2);

                //// 普通群发
                //// 下面是 3 个假设的号码
                // var res3 = sms.MultiSend(0, "86", phoneNumbers, "尊敬的会员，您重置密码的验证码是：123456，请于15分钟内输入，请勿外泄。询4008819016", "", "");
                // Console.WriteLine(JsonConvert.SerializeObject(res3));

                var res4 = sms.MultiSendWithParam("86", phoneNumbers, tmplId, templParams, "", "", "");
                Console.WriteLine(res4);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
    }
}
